package View;

import java.awt.event.ActionListener;

import Communication.Client;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;


import javax.swing.JButton;




import java.awt.Font;
import Entity.Cities;

import java.io.Serializable;

/** this class provide the GUI window for configuring pattern by entering all the information needed*/
public class PatternConfigView extends JFrame  implements Serializable{

	private static final long serialVersionUID = 42L;
	/**required  fields and buttons */
	JLabel ProductSelect;
	JLabel AgeRange;
	JLabel SelectCity;
	JLabel CustomerImportance;
	JLabel CustomerInterestingLevel;
	JLabel CustomerPermissionlevel;
	JLabel SelectID;
	JLabel SelectName;
	JTextField ProductSelectField;
	JComboBox SelectCityField;
	JComboBox CustomerImportanceField;
	JComboBox CustomerInterestingLevelField;
	JComboBox CustomerPermissionLevelField;
	JButton ConfigureButton;
	JButton BackButton;
	JLabel MassageToCustomer;
	JTextField MassageToCustomerField;
	JTextField PatternID;
	JTextField PatternName;
	private JTextField minage;
	private JTextField maxage;
	Client client;

	/** default and only constructor */
	public PatternConfigView() {
		this.setTitle("New Pattern Configuration");
		this.setSize(493,471);
		this.setLocationRelativeTo(null); 
		getContentPane().setLayout(null);

		ProductSelect = new JLabel("Select Product ID ");
		ProductSelect.setBounds(20, 11, 126, 26);
		ProductSelect.setFont(new Font("Tahoma", Font.BOLD, 12));
		getContentPane().add(ProductSelect);

		AgeRange = new JLabel("Age Range");
		AgeRange.setBounds(20, 48, 84, 26);
		AgeRange.setFont(new Font("Tahoma", Font.BOLD, 12));
		getContentPane().add(AgeRange);

		SelectCity = new JLabel("Select City ");
		SelectCity.setBounds(20, 85, 97, 21);
		SelectCity.setFont(new Font("Tahoma", Font.BOLD, 12));
		getContentPane().add(SelectCity);

		CustomerImportance = new JLabel("Customer Importance");
		CustomerImportance.setBounds(20, 109, 165, 34);
		CustomerImportance.setFont(new Font("Tahoma", Font.BOLD, 12));
		getContentPane().add(CustomerImportance);

		CustomerInterestingLevel = new JLabel("Customer Interesting-Level");
		CustomerInterestingLevel.setBounds(20, 139, 201, 36);
		CustomerInterestingLevel.setFont(new Font("Tahoma", Font.BOLD, 12));
		getContentPane().add(CustomerInterestingLevel);

		CustomerPermissionlevel = new JLabel("Customer Permissions Level ");
		CustomerPermissionlevel.setBounds(20, 182, 173, 26);
		CustomerPermissionlevel.setFont(new Font("Tahoma", Font.BOLD, 12));
		getContentPane().add(CustomerPermissionlevel);

		MassageToCustomer = new JLabel("Message To Customer");
		MassageToCustomer.setBounds(20, 293, 151, 14);
		MassageToCustomer.setFont(new Font("Tahoma", Font.BOLD, 12));
		getContentPane().add(MassageToCustomer);

		ProductSelectField = new JTextField();
		ProductSelectField.setBounds(196, 15, 145, 20);
		getContentPane().add(ProductSelectField);


		int x=10;
		String[] CustomerImportanceList = new String[x];
		for(int i=0;i<x;++i)
			CustomerImportanceList[i] = Integer.toString(i+1);
		CustomerImportanceField = new JComboBox(CustomerImportanceList);
		CustomerImportanceField.setBounds(195, 117, 145, 20);
		CustomerImportanceField.addActionListener(CustomerImportanceField);
		getContentPane().add(CustomerImportanceField);

		int y=10;
		String[] CustomerInterestingList = new String[y];
		for(int i=0;i<y;++i)
			CustomerInterestingList[i] = Integer.toString(i+1);
		CustomerInterestingLevelField = new JComboBox(CustomerInterestingList);
		CustomerInterestingLevelField.setBounds(196, 148, 145, 20);
		getContentPane().add(CustomerInterestingLevelField);

		int z=10;
		String[] CustomerPermissionList = new String[z];
		for(int i=0;i<z;++i)
			CustomerPermissionList[i] = Integer.toString(i+1);
		CustomerPermissionLevelField = new JComboBox(CustomerPermissionList);
		CustomerPermissionLevelField.setBounds(195, 186, 145, 20);
		getContentPane().add(CustomerPermissionLevelField);

		MassageToCustomerField = new JTextField();
		MassageToCustomerField.setBounds(158, 293, 245, 87);
		getContentPane().add(MassageToCustomerField);
		MassageToCustomerField.setColumns(10);

		ConfigureButton = new JButton("Configure");
		ConfigureButton.setBounds(249, 391, 120, 29);
		ConfigureButton.setFont(new Font("Tahoma", Font.BOLD, 15));
		getContentPane().add(ConfigureButton);

		BackButton = new JButton("Back");
		BackButton.setBounds(92, 391, 101, 29);
		BackButton.setFont(new Font("Tahoma", Font.BOLD, 15));
		getContentPane().add(BackButton);

		SelectID = new JLabel("Pattern ID");
		SelectID.setBounds(20, 222, 151, 14);
		SelectID.setFont(new Font("Tahoma", Font.BOLD, 12));
		getContentPane().add(SelectID);

		PatternID = new JTextField();
		PatternID.setBounds(196, 217, 145, 26);
		PatternID.setColumns(10);
		getContentPane().add(PatternID);

		PatternName = new JTextField();
		PatternName.setBounds(196, 253, 145, 26);
		PatternName.setColumns(10);
		getContentPane().add(PatternName);

		SelectName = new JLabel("Pattern Name");
		SelectName.setBounds(20, 258, 151, 14);
		SelectName.setFont(new Font("Tahoma", Font.BOLD, 12));
		getContentPane().add(SelectName);

		minage = new JTextField();
		minage.setBounds(174, 52, 73, 20);
		getContentPane().add(minage);
		minage.setColumns(10);

		JLabel lblNewLabel = new JLabel("Min Age");
		lblNewLabel.setBounds(125, 55, 46, 14);
		getContentPane().add(lblNewLabel);

		maxage = new JTextField();
		maxage.setBounds(360, 52, 73, 20);
		getContentPane().add(maxage);
		maxage.setColumns(10);

		JLabel lblNewLabel_1 = new JLabel("Max Age");
		lblNewLabel_1.setBounds(293, 55, 57, 14);
		getContentPane().add(lblNewLabel_1);

		SelectCityField = new JComboBox(Cities.getCitiesStringArr());
		SelectCityField.addActionListener( SelectCityField);
		SelectCityField.setBounds(196, 86, 145, 20);
		getContentPane().add(SelectCityField);

	}

	/**
	 * sets the list of cities
	 * @param listOfCities
	 */
	public void setCitys(String[] listOfCities){
		SelectCityField = new JComboBox<String>(listOfCities);
		SelectCityField.addActionListener(SelectCityField);

	}

	/**
	 * add listeners to add and back buttons function
	 * @param actionListener
	 */
	public void PatternConfigListener(ActionListener actionListener){
		ConfigureButton.addActionListener(actionListener);
		BackButton.addActionListener(actionListener);
	}

	/**
	 * show and hide window functions
	 */
	public void showWindow(){
		setVisible(true);
	}
	public void hideWindow(){
		setVisible(false);
	}	

	/**
	 * 
	 * @return text for field ProductID
	 */
	public String getProductID(){
		return  ProductSelectField.getText();
	}
	/**
	 * 
	 * @return selected item for field CustomerCity
	 */
	public String getCustomerCity(){
		return SelectCityField.getSelectedItem().toString();
	}
	/**
	 * 
	 * @return text for field MinAge
	 */
	public String getMinAge(){

		return minage.getText();
	}
	/**
	 * 
	 * @return text for field MaxAge
	 */
	public String getMaxAge(){

		return maxage.getText();
	}

	/**
	 * 
	 * @return text for field CustomerImportance
	 */
	public String getCustomerImportance(){
		return (String) CustomerImportanceField.getSelectedItem();
	}

	/**
	 * 
	 * @return text for field CustomerInterestingLevel
	 */
	public String getCustomerInteresting(){
		return (String) CustomerInterestingLevelField.getSelectedItem();
	}

	/**
	 * 
	 * @return text for field  CustomerPermissionLevel
	 */
	public String getCustomerPermission(){
		return  (String) CustomerPermissionLevelField.getSelectedItem();
	}
	
	/**
	 * 
	 * @return text for field PatternID
	 */
	public String getPatternID(){
		return PatternID.getText();
	}
	
	/**
	 * 
	 * @return text for field PatternName
	 */
	public String getPatternName(){
		return  PatternName.getText();
	}
	/**
	 * 
	 * @return text for field MassageToCustomer
	 */
	public String getMassageToCustomer(){
		return  MassageToCustomerField.getText();
	}
	/**
	 * 
	 * @return button ConfigureButton
	 */
	public  JButton getConfigureButton() {
		return this.ConfigureButton;
	}
	/**
	 * 
	 * @return button BackButton
	 */
	public  JButton getBackButton() {
		return this.BackButton;
	}



	public void clearFields()
	{
		ProductSelectField.setText(null);
		SelectCityField.setSelectedItem(null);
		CustomerImportanceField.setSelectedItem(null);
		CustomerInterestingLevelField.setSelectedItem(null);
		CustomerPermissionLevelField.setSelectedItem(null);
		MassageToCustomerField.setText(null);
		maxage.setText(null);
		PatternID.setText(null);
		PatternName.setText(null);
		minage.setText(null);

	}
}